def content_word_sort(content):
    import re
    with open(content,encoding='utf-8') as f:
        all_word = f.read()
        all_result = re.split("[\. ,( )'-/\\ = \\n]",all_word.lower())   #过滤单词

        #以字典形式添加单词及次数
        result_dict = {}
        for i in all_result:
            if i in result_dict:
                result_dict[i] += 1
            else:
                result_dict[i] = 1
    return  sorted(result_dict.items(),key=lambda x:x[1],reverse=True)[1:11]

print(content_word_sort('C:/file/python 课件/sample.txt'))


# 效率差一些，如果文件很大的话，需要的内存会很多







